# -*- coding: utf-8 -*-
from liberHook.BaseHook import BaseHook
import hou


class Hook(BaseHook):
    def __init__(self, library, directory, ext, start, end):
        BaseHook.__init__(self, library, directory, ext, start, end)

    def execute(self):
        if not self.files:
            self.append_error("No houdini files found.")
            return
        hdr = self.files[0]
        selected_nodes = hou.selectedNodes()
        if not selected_nodes:
            self.append_error("No houdini node selected.")
            return
        node = selected_nodes[0]
        gen = node.parm('env_map')
        if gen is None:
            gen = node.parm('ar_light_color_texture')
        if gen is None:
            gen = node.parm('A_FILENAME')
        gen.set(hdr)
